from feapder import UpdateItem
from datetime import datetime
from feapder.utils import tools


class AmazonDetailItem(UpdateItem):

    __unique_key__ = ["asin"]  # 指定去重的key为 title、url，最后的指纹为title与url值联合计算的md5

    def __init__(self, *args, **kwargs):
        self.asin = None
        self.url = None
        self.cids = None
        self.parent_asin = None
        self.title = None
        self.cate_info = None
        self.cover = None
        self.cover_list = None
        self.shop_name = None
        self.shop_url = None
        self.rank_info = None
        self.sold_info = None
        self.price_info = None
        self.sku_info = None
        self.about_info = None
        self.feature_info = None
        self.videos_info = None
        self.product_info = None
        self.other_seller_info = None
        self.comment_num = None
        self.score_info = None
        self.customer_tag = None

    def pre_to_db(self):
        """
        入库前的处理
        """
        data = self.__dict__
        self.update_time = datetime.now()
        for k, v in self.__dict__.items():
            if isinstance(v, dict):
                self.__dict__[k] = tools.json.dumps(v)
